package bookpos.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import bookpos.dao.BookDao;
import bookpos.entity.Book;
import bookpos.service.InventoryService;
/**
 * 账户业务实现类
 * @author WZB
 *
 */
@Service
public class InventoryServiceImpl implements InventoryService {
	@Autowired
	private BookDao dao;


	public List<Book> findAll(int page, int rows, String sort, String order) {
		return dao.findAll(page, rows, sort, order);
	}

	public int getTotal() {
		return dao.countAll();
	}

	public boolean addInventory(Integer id, Integer quantity) {
		return dao.addInventory(id,quantity);
		
	}

	public boolean subInventory(Integer id, Integer quantity) {
		return dao.subInventory(id,quantity);
		
	}

	public Book findById(Integer id) {
		return dao.get("from Book where id="+id);
	}

	public void returnGoods(String[] ids, String[] qs) {
		if(ids.length == qs.length){
			int leng = ids.length;
			for(int i=0;i<leng;i++){
                String sql = "update bookpos_book set quantity=quantity+"+qs[i]+" where id="+ids[i];
				dao.doUpdateBySQL(sql);
			}
		}
		
	}
	
	public void saleGoods(String[] ids, String[] qs) {
		if(ids.length == qs.length){
			int leng = ids.length;
			for(int i=0;i<leng;i++){
				 String sql = "update bookpos_book set quantity=quantity-"+qs[i]+" where id="+ids[i];
				 dao.doUpdateBySQL(sql);
			}
		}
		
	}

}
